// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) braces deadcode fieldsfirst 

package net.minecraft;


import java.awt.*;
import java.awt.event.*;
import java.awt.image.VolatileImage;
import java.io.*;
import java.util.*;

import javax.imageio.ImageIO;

// Referenced classes of package net.minecraft:
//            MinecraftUtil, LauncherFrame

public class SettingsPanel extends Panel
{
	private static final long serialVersionUID = 1L;
    private Image bgImage;
    private ArrayList<Checkbox> boxes = new ArrayList<Checkbox>();
    private Button cancelButton;
    private Button saveButton;
    private Button openManager;
    private Choice updateChannel;
    private LauncherFrame lf;
    private VolatileImage img;
    public SettingsPanel(LauncherFrame launcherframe)
    {
        boxes.add(new Checkbox("Download update to minecraft.jar instead of selected jar file."));
        boxes.add(new Checkbox("Backup .jar file before update."));
        updateChannel = new Choice();
        updateChannel.add("Official");
        updateChannel.add("djmati11s");
        updateChannel.add("Random Cheat Client");
        saveButton = new Button("Save");
        cancelButton = new Button("Cancel");
        openManager = new Button("Backup Manager");
        lf = launcherframe;
        GridBagLayout gridbaglayout = new GridBagLayout();
        setLayout(gridbaglayout);
        add(buildSettingsPanel());
        try
        {
            bgImage = ImageIO.read((net.minecraft.LoginForm.class).getResource("dirt.png")).getScaledInstance(32, 32, 16);
        }
        catch(IOException ioexception)
        {
            ioexception.printStackTrace();
        }
        
    }

    

    public void update(Graphics g)
    {
        paint(g);
    }

    public void paint(Graphics g)
    {

        int i = getWidth() / 2;
        int j = getHeight() / 2;
        if(img == null || img.getWidth() != i || img.getHeight() != j)
        {
            img = createVolatileImage(i, j);
        }
        Graphics g1 = img.getGraphics();
        for(int k = 0; k <= i / 32; k++)
        {
            for(int l = 0; l <= j / 32; l++)
            {
                g1.drawImage(bgImage, k * 32, l * 32, null);
            }

        }

        g1.setColor(Color.LIGHT_GRAY);
        String s = "Launcher Settings";
        g1.setFont(new Font(null, 1, 20));
        FontMetrics fontmetrics = g1.getFontMetrics();
        g1.drawString(s, i / 2 - fontmetrics.stringWidth(s) / 2, j / 2 - fontmetrics.getHeight() * 2);
        g1.dispose();
        g.drawImage(img, 0, 0, i * 2, j * 2, null);
    }

    private Panel buildSettingsPanel()
    {
        Panel panel = new Panel() {

            private static final long serialVersionUID = 1L;
            private Insets insets;

            public Insets getInsets()
            {
                return insets;
            }

            public void update(Graphics g)
            {
                paint(g);
            }

            public void paint(Graphics g)
            {
                super.paint(g);
                int i = 0;
                g.setColor(Color.BLACK);
                g.drawRect(0, 0 + i, getWidth() - 1, getHeight() - 1 - i);
                g.drawRect(1, 1 + i, getWidth() - 3, getHeight() - 3 - i);
                g.setColor(Color.WHITE);
                g.drawRect(2, 2 + i, getWidth() - 5, getHeight() - 5 - i);
            }

            
            {
                insets = new Insets(12, 24, 16, 32);
            }
        }
;
        panel.setBackground(Color.GRAY);
        BorderLayout borderlayout = new BorderLayout();
        borderlayout.setHgap(0);
        borderlayout.setVgap(8);
        panel.setLayout(borderlayout);
        GridLayout gridlayout = new GridLayout(0, 1);
        GridLayout gridlayout1 = new GridLayout(0, 1);
        gridlayout.setVgap(2);
        gridlayout1.setVgap(2);
        Panel panel1 = new Panel(gridlayout);
        Panel panel2 = new Panel(gridlayout1);
        for (Checkbox c : boxes)
        {

            panel1.add(new Label("", 2));//
            panel2.add(c);//
        	
        }
        panel1.add(new Label("Update channel:", 2));
        panel2.add(updateChannel);
        panel.add(panel1, "West");
        panel.add(panel2, "Center");
        Panel panel3 = new Panel(new BorderLayout());
        cancelButton.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent actionevent)
            {
            	lf.showLogin();
            }

        }
);
        saveButton.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent actionevent)
            {
            	lf.settingspanel.writeSettings();
            	MinecraftUtil.readSettings();
            	lf.showLogin();
            }

        }
);
        openManager.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent actionevent)
            {
            	lf.showBackup();
            	
            }

        }
);
        panel3.add(cancelButton, "West");
        panel3.add(openManager, "Center");
        panel3.add(saveButton, "East");
        

      
        panel.add(panel3, "South");
        return panel;
    }
    public void readSettings()
    {
        try
        {
            File file = new File(MinecraftUtil.getWorkingDirectory(), "lsettings");
            DataInputStream datainputstream;
            datainputstream = new DataInputStream(new FileInputStream(file));
            boolean flag = false;
            int k = 0;
            while (datainputstream.available() >= 1)
            {
            		if (k >= boxes.size())
            		{
            			updateChannel.select(Character.digit(datainputstream.readChar(), 10));
            			break;
            		}
            		
            		if (datainputstream.readChar() == '1')
            		{
            			flag = true;
            		} else {
            			flag = false;
            		}
            		boxes.get(k).setState(flag);
            		k++;
            }
            datainputstream.close();
        }
        catch(Exception exception)
        {
            exception.printStackTrace();
        }
       
    }

    public void writeSettings()
    {
        try
        {
            File file = new File(MinecraftUtil.getWorkingDirectory(), "lsettings");
            DataOutputStream dataoutputstream;
            dataoutputstream = new DataOutputStream(new FileOutputStream(file));
            for (Checkbox c : boxes)
    		{
            	if (c.getState())
            	{
            		dataoutputstream.writeChar('1');
            	} else {
            		dataoutputstream.writeChar('0');
            		
            	}
            	
    		}
    		dataoutputstream.writeChar(Character.forDigit(updateChannel.getSelectedIndex(), 10));
            dataoutputstream.close();
        }
        catch(Exception exception)
        {
            exception.printStackTrace();
        }
    }


}
